package com.qqtech.qquan.pub.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtech.agent.context.AdminPage;
import com.qqtech.core.common.enums.YesNoEnum;
import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.pub.model.PubUpgradeVersion;
import com.qqtech.qquan.pub.model.PubUpgradeVersionQuery;
import com.qqtech.qquan.pub.model.PubUpgradeVersionVo;
import com.qqtech.qquan.pub.service.PubUpgradeVersionService;
import com.qqtech.qquan.sys.controller.BaseAgentController;

@Controller
@RequestMapping(value = "/pub/upgradeversion")
public class PubUpgradeVersionController extends BaseAgentController {

	@Resource
	private PubUpgradeVersionService pubUpgradeVersionService;

	@Override
	protected BaseService<PubUpgradeVersion> getBaseService() {
		return pubUpgradeVersionService;
	}

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list() {
		return "/pubUpgrade/pubUpgradeversion-list";
	}

	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public AdminPage list(PubUpgradeVersionQuery query, HttpServletRequest request, HttpServletResponse response) {
		AdminPage adminPage = new AdminPage();
		String rows = (String) request.getParameter("rows"); // 每页条数
		query.setSize(Integer.valueOf(rows));
		Pageable pageKit = new PageKit(query.getPage(),query.getSize(), new PageOrder(Direction.DESC, "id"));
		Page<PubUpgradeVersionVo> page = pubUpgradeVersionService.queryPageList(query, pageKit);
		adminPage.setRows(page.getContent());
		adminPage.setTotal(Integer.valueOf(page.getTotalElements() + ""));
		return adminPage;
	}

	@RequestMapping(value = "/toAdd")
	public String toAdd(Model model) {
		return "/pubUpgrade/pubUpgradeversion-add";
	}

	/**
	 * 创建成功
	 * 
	 * @param add
	 * @return
	 */
	@RequestMapping(value = "/add")
	@ResponseBody
	public Result add(PubUpgradeVersion add) {
		Result ret = new Result();
		pubUpgradeVersionService.insert(add);
		return ret;
	}

	@RequestMapping(value = "/toUpdate")
	public String toUpdate(Integer id, Model model) {
		PubUpgradeVersion update = pubUpgradeVersionService.getById(id);
		model.addAttribute("update", update);
		return "/pubUpgrade/pubUpgradeversion-update";
	}

	/**
	 * 更新
	 * 
	 * @param add
	 * @return
	 */
	@RequestMapping(value = "/update")
	@ResponseBody
	public Result update(PubUpgradeVersion update) {
		Result ret = new Result();
		pubUpgradeVersionService.updateById(update);
		return ret;
	}

	/**
	 * 删除
	 * 
	 * @param del
	 * @return
	 */
	@RequestMapping(value = "/del")
	@ResponseBody
	public Result del(Integer id) {
		Result ret = new Result();
		pubUpgradeVersionService.deleteById(id);
		return ret;
	}

	/**
	 * 确认
	 * 
	 * @param overrideMsgId
	 * @return
	 */
	@RequestMapping(value = "/confirm")
	@ResponseBody
	public Result confirm(String overrideMsgId) {
		Result ret = new Result();
		return ret;
	}
}
